package com.example.ggg.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class MyCustomEventListener implements ApplicationListener<MyCustomEvent> {
    @Override
    public void onApplicationEvent(MyCustomEvent event) {

    }

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    public void publishEvent() {
        System.out.println("Publishing custom event. ");
        MyCustomEvent customEvent = new MyCustomEvent(this);
        applicationEventPublisher.publishEvent(customEvent);
    }
}
